<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
  <title>系统常态化运行评分系统</title>
  <link rel="stylesheet" href="../../component/pear/css/pear.css" />
</head>

<body class="pear-container">
<div class="layui-card">
  <div class="layui-card-header">矿井基本信息</div>
  <div class="layui-card-body">
    <form class="layui-form" action="" onsubmit="return false" lay-filter="lay-info">
      <div class="layui-form-item">
        <div class="layui-form-label">矿井名称</div>
        <div class="layui-input-block">
          <input type="text"  name="mineName"  disabled="disabled"  placeholder="矿井名称" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">矿井类别</label>
        <div class="layui-input-block">
          <input type="text" name="mineType" disabled="disabled" placeholder="矿井类别" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
          <label class="layui-form-label">特殊类型</label>
          <div class="layui-input-block">
              <input type="checkbox" name="mineState" title="瓦斯智能抽采" value="1" lay-skin="primary">
							<input type="checkbox" name="mineState" title="瓦斯智能防突" value="2" lay-skin="primary">
							<input type="checkbox" name="mineState" title="立井提升"  value="3" lay-skin="primary">
							<input type="checkbox" name="mineState" title="轨道运输"  value="4" lay-skin="primary">
          </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label">简介</label>
        <div class="layui-input-block">
          <textarea name="remark" id="remark" cols="30" rows="10"></textarea>
        </div>
      </div>
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="pear-btn pear-btn-primary" lay-submit lay-filter="lay-modify-login-pwd">修改矿井基本信息</button>
        </div>
      </div>
    </form>
  </div>
</div>
<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script src="../../scripts/utils/request.js"></script>
<script src="../../scripts/utils/auth.js"></script>
<script src="../../scripts/utils/tinymceUtils.js"></script>
<script>
  var $,form,popup,notice,tinymce
  layui.use(['form', 'jquery','popup','notice','tinymce','util','tinymce'], function() {
    form = layui.form;
    $ = layui.jquery;
    popup = layui.popup;
    notice = layui.notice;
    tinymce= layui.tinymce;
    util= layui.util;
    var tinymce=layui.tinymce;

    var remark=initTinymce(tinymce,'remark');

    var id;
    function setCheckBoxValues(value){
      if(!value||value==''){
        return;
      }
      //给checkbox赋值
      var unitType = [];
      unitType = value.split(",");
      for (var j = 0; j < unitType.length; j++) {
          var unitTypeCheckbox =$("input[name=mineState]");
          for (var i = 0; i < unitTypeCheckbox.length; i++) {
              if (unitTypeCheckbox[i].value == unitType[j]) {
                  unitTypeCheckbox[i].checked = true;
              }
          }
      }
      form.render();
    }

    function getCheckBoxValues(){
      let mineState='';
      var unitTypeCheckbox =$("input[name=mineState]");
      for (var i = 0; i < unitTypeCheckbox.length; i++) {
          if (unitTypeCheckbox[i].checked) {
            mineState+=','+unitTypeCheckbox[i].value;
          }
      }
      if(mineState.length>0){
        mineState=mineState.substring(1);
      }
      return mineState;
    }



    //请求接口获取个人基本信息（主要是根据需要获取评分密码）

    postAjaxNoSuccessTip('/api/mine/getMineInfo',null,function (response){
      form.val('lay-info', {
        "mineName": response.data.mineName,
        "mineType": response.data.mineType,
        "remark":response.data.remark
      });
      id=response.data.id;
      setCheckBoxValues(response.data.mineState)
    },null);


    form.on('submit(lay-modify-login-pwd)', function (data) {
      let reqData=data.field;
      reqData.id=id;
      reqData.mineState= getCheckBoxValues();
      reqData.remark=remark.getContent();
      postAjax('/api/mine/modify',reqData,function (response){

      },null);
    });
    // 自定义验证规则
    form.verify({
      password: function (value) {
        if (!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@#$%^&+=!])(?!.*\s).{4,50}$/.test(value)) {
          return '请输入正确的密码格式（ps:至少包含大写字母、数字、特殊符号）';
        }
      }
    });


  });
</script>
</body>
</html>